package com.demo.project_template.service.impl;

import com.demo.project_template.entity.SystemConfig;
import com.demo.project_template.mapper.SystemConfigMapper;
import com.demo.project_template.service.SystemConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.project_template.util.RedisUtil;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.util.List;

import static com.demo.project_template.constant.CommonConstants.SYSTEM_CONFIG;

/**
 * <p>
 * 系统配置 服务实现类
 * </p>
 *
 * @author 杨玉龙
 * @since 2023-06-19 15:56:44
 */
@Service
public class SystemConfigServiceImpl extends ServiceImpl<SystemConfigMapper, SystemConfig> implements SystemConfigService {

    @Resource
    private SystemConfigMapper systemConfigMapper;

    @Override
    @Cacheable(value = SYSTEM_CONFIG)
    public SystemConfig selectSystemConfig() {
        return systemConfigMapper.selectList(null).get(0);
    }

    @Override
    @CachePut(value = SYSTEM_CONFIG)
    public void updateSystemConfig(SystemConfig systemConfig) {
        systemConfigMapper.updateById(systemConfig);
        //redisUtil.set(CommonConstants.SYSTEM_CONFIG,JSON.toJSONString(systemConfig));
    }
}
